package cn._51doit.flink.day02.transformations;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.typeinfo.TypeHint;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.operators.StreamFlatMap;
import org.apache.flink.streaming.api.operators.StreamMap;

/**
 * 不直接调用map方法，而是调用transform方法实现与map方法一样的功能！
 *
 * map算子底层的实现是什么样的？
 *
 * map方法底层调用的是transform方法，出入三个参数
 * 第一个：算子的名称
 * 第二个：返回的类型
 * 第三个：数据具体怎样处理的实现类
 *
 *
 */
public class MapDemo4 {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //spark
        DataStreamSource<String> lines = env.socketTextStream("localhost", 8888);

        MapFunction<String, String> mapFunction = new MapFunction<String, String>() {
            @Override
            public String map(String w) throws Exception {
                return w.toUpperCase();
            }
        };
        //SPARK
        SingleOutputStreamOperator<String> res = lines.transform("MyMap", TypeInformation.of(String.class), new StreamMap<>(mapFunction));

        res.print();

        env.execute();
    }

}
